package response;

import article.Article;
import course.shared.PMF;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;
import java.util.*;
import java.text.*;

/**
 * Servlet implementation class addReServlet
 */
public class addReServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		String responser = request.getParameter("id");
		Long article = Long.parseLong(request.getParameter("article"));
		String cont = request.getParameter("content");
				
		java.util.Date d1 = new java.util.Date();
		SimpleDateFormat sdfmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		d1 = cal.getTime();
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			Article a = pm.getObjectById(Article.class,article);
			a.addRe(a, cont, sdfmt.format(d1), responser);
		} finally {
		    pm.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
